﻿
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

using ConstructionBidOnline.DAL;
using ConstructionBidOnline.DAL.dsLookUpsTableAdapters;


namespace ConstructionBidOnline.Biz
{
    public sealed partial class LookupCacheManager
    {
        #region Public Properties

        /// <summary>
        /// Gets the cached instance of the AppUsersLookup.
        /// </summary>
        public static SubAdminsLookup Users
        {
            get
            {
                if (Cache[typeof(SubAdminsLookup)] == null)
                    Cache[typeof(SubAdminsLookup)] = new SubAdminsLookup();

                return (SubAdminsLookup)Cache[typeof(SubAdminsLookup)];
            }
        }


        ///// <summary>
        ///// Gets the cached instance of MIMETypesLookup (aka LU_MIMETypes).
        ///// </summary>
        //public static MIMETypesLookup MIMETypes
        //{
        //    get
        //    {
        //        if (Cache[typeof(MIMETypesLookup)] == null)
        //            Cache[typeof(MIMETypesLookup)] = new MIMETypesLookup();

        //        return (MIMETypesLookup)Cache[typeof(MIMETypesLookup)];
        //    }
        //}


        /// <summary>
        /// Gets the cached instance of RbsRolesLookup (aka LU_RBSRoles).
        /// </summary>
        public static RbsRolesLookup RbsRoles
        {
            get
            {
                if (Cache[typeof(RbsRolesLookup)] == null)
                    Cache[typeof(RbsRolesLookup)] = new RbsRolesLookup();

                return (RbsRolesLookup)Cache[typeof(RbsRolesLookup)];
            }
        }


        ///// <summary>
        ///// Gets the cached instance of StatesLookup (aka LU_States).
        ///// </summary>
        //public static StatesLookup States
        //{
        //    get
        //    {
        //        if (Cache[typeof(StatesLookup)] == null)
        //            Cache[typeof(StatesLookup)] = new StatesLookup();

        //        return (StatesLookup)Cache[typeof(StatesLookup)];
        //    }
        //}


        ///// <summary>
        ///// Gets the cached instance of GeographicLocationsLookup (aka LU_GeographicLocations).
        ///// </summary>
        //public static GeographicLocationsLookup GeographicLocations
        //{
        //    get
        //    {
        //        if (Cache[typeof(GeographicLocationsLookup)] == null)
        //            Cache[typeof(GeographicLocationsLookup)] = new GeographicLocationsLookup();

        //        return (GeographicLocationsLookup)Cache[typeof(GeographicLocationsLookup)];
        //    }
        //}


        ///// <summary>
        ///// Gets the cached instance of PostalCodesLookup (aka LU_PostalCodes).
        ///// </summary>
        //public static PostalCodesLookup PostalCodes
        //{
        //    get
        //    {
        //        if (Cache[typeof(PostalCodesLookup)] == null)
        //            Cache[typeof(PostalCodesLookup)] = new PostalCodesLookup();

        //        return (PostalCodesLookup)Cache[typeof(PostalCodesLookup)];
        //    }
        //}

        #endregion
    }

    #region SubAdmin

    public class SubAdminsElement : LookupElement
    {
        #region Construction / Disposal

        public SubAdminsElement(int userID, string titleOfCourtesy, string firstName,
                                string lastName, bool isActive)

            : base(userID, firstName + " " + lastName, 0, null, isActive)
        {
            TitleOfCourtesy = titleOfCourtesy;
            FirstName = firstName;
            LastName = lastName;
        }

        #endregion

        #region Public Properties

        //--------------------------------------------------------------------------
        // Aliases for the LookupElement.Value and LookupElement.Text fields.
        public int UserID
        {
            get { return base.Value; }
            set { base.Value = value; }
        }


        public string FirstNameLastName
        {
            get { return (base.Text); }
            set { base.Text = value; }
        }


        //--------------------------------------------------------------------------
        // Lookup table-specific fields/columns that are not already contained in LookupElement.
        public string TitleOfCourtesy
        {
            get { return (_titleOfCourtesy); }
            set { _titleOfCourtesy = value; }
        } private string _titleOfCourtesy = "";


        public string FirstName
        {
            get { return (_firstName); }
            set { _firstName = value; }
        } private string _firstName = "";


        public string LastName
        {
            get { return (_lastName); }
            set { _lastName = value; }
        } private string _lastName = "";


        #endregion
    }


    public partial class SubAdminsLookup : Lookup<SubAdminsElement>
    {
        #region Construction / Disposal

        public SubAdminsLookup()
        {
            this.Load(AppSettings.AppVersion);
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Load the lookup values from the database.
        /// </summary>
        public override void Load(string version)
        {
            // For now...do not pre-load all of the Users. Once an actual application is in-place
            // it would be appropriate/smart to load all of the Users from the same Customer/Company
            // or some other logical group to which the logged-on user belongs.
            return;

            //AppUsersTableAdapter adapter = new AppUsersTableAdapter();
            //adapter.Connection = AppSettings.GetDbConn();

            //dsLookups.AppUsersDataTable tbl = adapter.GetData(null, null);

            //foreach (dsLookups.AppUsersRow row in tbl.Rows)
            //    this.Add(new AppUsersElement(row.UserID, row.TitleOfCourtesy, row.FirstName, row.MiddleName, row.LastName, row.NameSuffix, row.IsActive));
        }


        /// <summary>
        /// Loads the single specified element if it's not already in the collection.
        /// </summary>
        public override SubAdminsElement LoadOneByID(int pkid)
        {
            // Make sure we don't already have it.
            foreach (SubAdminsElement obj in this)
            {
                if (obj.Value == pkid)
                    return (obj);
            }

            SubAdminTableAdapter adapter = new SubAdminTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            SubAdminsElement elem = null;
            dsLookUps.SubAdminDataTable tbl = adapter.GetData(pkid);
            if (tbl.Rows.Count == 1)
            {
                dsLookUps.SubAdminRow row = (dsLookUps.SubAdminRow)tbl.Rows[0];

                elem = new SubAdminsElement(
                    row.UserID,
                    row.IsTitleOfCourtesyNull() ? "" : row.TitleOfCourtesy,
                    row.FirstName,
                    row.LastName,
                    row.IsActive);

                this.Add(elem);
            }

            return (elem);
        }


        public string UserFirstNameLastNameFromUserID(int userID)
        {
            string retVal;

            SubAdminsElement elem = LoadOneByID(userID);

            if (elem != null)
                retVal = elem.FirstName + " " + elem.LastName;
            else retVal = "*Error: UserID=" + userID.ToString() + " could not be located.";

            return (retVal);
        }


        public string UserLastNameFirstNameFromUserID(int userID)
        {
            string retVal;

            SubAdminsElement elem = LoadOneByID(userID);

            if (elem != null)
                retVal = elem.LastName + ", " + elem.FirstName;
            else retVal = "*Error: UserID=" + userID.ToString() + " could not be located.";

            return (retVal);
        }

        #endregion
    }

    #endregion

    //#region LU_States

    //public class StatesElement : LookupElement
    //{
    //    #region Construction / Disposal

    //    public StatesElement(int stateID, string stateName, string stateCode, string version, bool isActive)

    //        : base(stateID, stateName, 0, version, isActive)
    //    {
    //        StateCode = stateCode;
    //    }

    //    #endregion

    //    #region Public Properties

    //    --------------------------------------------------------------------------
    //     Aliases for the LookupElement.Value and LookupElement.Text fields.
    //    public int LU_StateID
    //    {
    //        get { return base.Value; }
    //        set { base.Value = value; }
    //    }


    //    public string StateName
    //    {
    //        get { return (base.Text); }
    //        set { base.Text = value; }
    //    }


    //    --------------------------------------------------------------------------
    //     Lookup table-specific fields/columns that are not already contained in LookupElement.
    //    public string StateCode
    //    {
    //        get { return (_stateCode); }
    //        set { _stateCode = value; }
    //    } private string _stateCode = "";

    //    #endregion
    //}


    //public partial class StatesLookup : Lookup<StatesElement>
    //{
    //    #region Construction / Disposal

    //    public StatesLookup()
    //    {
    //        this.Load(AppSettings.AppVersion);
    //    }

    //    #endregion

    //    #region Public Methods

    //     <summary>
    //     Load the lookup values from the database.
    //     </summary>
    //    public override void Load(string version)
    //    {
    //        LU_StatesTableAdapter adapter = new LU_StatesTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        dsLookups.LU_StatesDataTable tbl = adapter.GetData(null, null);

    //        foreach (dsLookups.LU_StatesRow row in tbl.Rows)
    //            this.Add(new StatesElement(row.LU_StateID, row.StateName, row.StateCode, row.IsVersionNull() ? null : row.Version, row.IsActive));
    //    }


    //     <summary>
    //     Loads the single specified element if it's not already in the collection.
    //     </summary>
    //    public override StatesElement LoadOneByID(int pkid)
    //    {
    //         Make sure we don't already have it.
    //        foreach (StatesElement obj in this)
    //        {
    //            if (obj.Value == pkid)
    //                return (obj);
    //        }

    //        LU_StatesTableAdapter adapter = new LU_StatesTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        StatesElement elem = null;
    //        dsLookups.LU_StatesDataTable tbl = adapter.GetData(pkid, null);
    //        if (tbl.Rows.Count == 1)
    //        {
    //            dsLookups.LU_StatesRow row = (dsLookups.LU_StatesRow)tbl.Rows[0];
    //            elem = new StatesElement(row.LU_StateID, row.StateName, row.StateCode, row.Version, row.IsActive);
    //            this.Add(elem);
    //        }

    //        return (elem);
    //    }

    //    #endregion
    //}

    //#endregion

    //#region LU_MIMETypes

    //public class MIMETypesElement : LookupElement
    //{
    //    #region Construction / Disposal

    //    public MIMETypesElement(int mimeTypeID, string fileExtension, string mimeType, bool isPermittedFileExtension,
    //                            string description, int displayOrder, string version, bool isActive)

    //        : base(mimeTypeID, mimeType, displayOrder, version, isActive)
    //    {
    //        base.Description = description;
    //        FileExtension = fileExtension;
    //        IsPermittedFileExtension = isPermittedFileExtension;
    //    }

    //    #endregion

    //    #region Public Properties

    //    --------------------------------------------------------------------------
    //     Aliases for the LookupElement.Value and LookupElement.Text fields.
    //    public int LU_MIMETypeID
    //    {
    //        get { return base.Value; }
    //        set { base.Value = value; }
    //    }


    //    public string MIMEType
    //    {
    //        get { return (base.Text); }
    //        set { base.Text = value; }
    //    }

    //    --------------------------------------------------------------------------
    //     Lookup table-specific fields/columns that are not already contained in LookupElement.
    //    public string FileExtension
    //    {
    //        get { return (_fileExtension); }
    //        set { _fileExtension = value; }
    //    } private string _fileExtension = "";


    //    public bool IsPermittedFileExtension
    //    {
    //        get { return (_isPermittedFileExtension); }
    //        set { _isPermittedFileExtension = value; }
    //    } private bool _isPermittedFileExtension = false;

    //    #endregion
    //}


    //public partial class MIMETypesLookup : Lookup<MIMETypesElement>
    //{
    //    #region Construction / Disposal

    //    public MIMETypesLookup()
    //    {
    //        this.Load(AppSettings.AppVersion);
    //    }

    //    #endregion

    //    #region Public Methods

    //     <summary>
    //     Load the lookup values from the database.
    //     </summary>
    //    public override void Load(string version)
    //    {
    //        LU_MIMETypesTableAdapter adapter = new LU_MIMETypesTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        dsLookups.LU_MIMETypesDataTable tbl = adapter.GetData(null, version);

    //        foreach (dsLookups.LU_MIMETypesRow row in tbl.Rows)
    //            this.Add(new MIMETypesElement(row.LU_MIMETypeID, row.FileExtension, row.MIMEType, row.IsPermittedFileExtension, row.IsDescriptionNull() ? null : row.Description, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive));
    //    }


    //     <summary>
    //     Loads the single specified element if it's not already in the collection.
    //     </summary>
    //    public override MIMETypesElement LoadOneByID(int pkid)
    //    {
    //         Make sure we don't already have it.
    //        foreach (MIMETypesElement obj in this)
    //        {
    //            if (obj.Value == pkid)
    //                return (obj);
    //        }

    //        LU_MIMETypesTableAdapter adapter = new LU_MIMETypesTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        MIMETypesElement elem = null;
    //        dsLookups.LU_MIMETypesDataTable tbl = adapter.GetData(pkid, null);
    //        if (tbl.Rows.Count == 1)
    //        {
    //            dsLookups.LU_MIMETypesRow row = (dsLookups.LU_MIMETypesRow)tbl.Rows[0];
    //            elem = new MIMETypesElement(row.LU_MIMETypeID, row.FileExtension, row.MIMEType, row.IsPermittedFileExtension, row.Description, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive);
    //            this.Add(elem);
    //        }

    //        return (elem);
    //    }

    //    #endregion
    //}

    //#endregion

    #region LU_RBSRoles

    public class RbsRolesElement : LookupElement
    {
        #region Construction / Disposal

        public RbsRolesElement(int rbsRoleID, string roleName, string description, int displayOrder, string version, bool isActive)

            : base(rbsRoleID, roleName, displayOrder, version, isActive)
        {
            base.Description = description;
        }

        #endregion

        #region Public Properties

        //--------------------------------------------------------------------------
        // Aliases for the LookupElement.Value and LookupElement.Text fields.
        public int LU_RBSRoleID
        {
            get { return base.Value; }
            set { base.Value = value; }
        }


        public string RoleName
        {
            get { return (base.Text); }
            set { base.Text = value; }
        }

        #endregion
    }


    public partial class RbsRolesLookup : Lookup<RbsRolesElement>
    {
        #region Construction / Disposal

        public RbsRolesLookup()
        {
            this.Load(AppSettings.AppVersion);
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Load the lookup values from the database.
        /// </summary>
        public override void Load(string version)
        {
            LU_RBSRolesTableAdapter adapter = new LU_RBSRolesTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            dsLookUps.LU_RBSRolesDataTable tbl = adapter.GetData(null, version);

            foreach (dsLookUps.LU_RBSRolesRow row in tbl.Rows)
                this.Add(new RbsRolesElement(row.LU_RoleID, row.RoleName, row.Description, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive));
        }


        /// <summary>
        /// Loads the single specified element if it's not already in the collection.
        /// </summary>
        public override RbsRolesElement LoadOneByID(int pkid)
        {
            // Make sure we don't already have it.
            foreach (RbsRolesElement obj in this)
            {
                if (obj.Value == pkid)
                    return (obj);
            }

            LU_RBSRolesTableAdapter adapter = new LU_RBSRolesTableAdapter();
            adapter.Connection = AppSettings.GetDbConn();

            RbsRolesElement elem = null;
            dsLookUps.LU_RBSRolesDataTable tbl = adapter.GetData(pkid, null);
            if (tbl.Rows.Count == 1)
            {
                dsLookUps.LU_RBSRolesRow row = (dsLookUps.LU_RBSRolesRow)tbl.Rows[0];
                elem = new RbsRolesElement(row.LU_RoleID, row.RoleName, row.Description, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive);
                this.Add(elem);
            }

            return (elem);
        }

        #endregion
    }

    #endregion

    //#region LU_GeographicLocations

    //public class GeographicLocationsElement : LookupElement
    //{
    //    #region Construction / Disposal

    //    public GeographicLocationsElement(int geographicLocationID, string geographicLocation, string description, int displayOrder, string version, bool isActive)
    //        : base(geographicLocationID, geographicLocation, displayOrder, version, isActive)
    //    {
    //        base.Description = description;
    //    }

    //    #endregion

    //    #region Public Properties

    //    //--------------------------------------------------------------------------
    //    // Aliases for the LookupElement.Value and LookupElement.Text fields.
    //    public int LU_GeographicLocationID
    //    {
    //        get { return base.Value; }
    //        set { base.Value = value; }
    //    }


    //    public string GeographicLocation
    //    {
    //        get { return (base.Text); }
    //        set { base.Text = value; }
    //    }

    //    #endregion
    //}


    //public partial class GeographicLocationsLookup : Lookup<GeographicLocationsElement>
    //{
    //    #region Construction / Disposal

    //    public GeographicLocationsLookup()
    //    {
    //        this.Load(AppSettings.AppVersion);
    //    }

    //    #endregion

    //    #region Public Methods

    //    /// <summary>
    //    /// Load the lookup values from the database.
    //    /// </summary>
    //    public override void Load(string version)
    //    {
    //        LU_GeographicLocationsTableAdapter adapter = new LU_GeographicLocationsTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        dsLookups.LU_GeographicLocationsDataTable tbl = adapter.GetData(null, version);

    //        foreach (dsLookups.LU_GeographicLocationsRow row in tbl.Rows)
    //            this.Add(new GeographicLocationsElement(row.LU_GeographicLocationID, row.GeographicLocation, row.Description, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive));
    //    }


    //    /// <summary>
    //    /// Loads the single specified element if it's not already in the collection.
    //    /// </summary>
    //    public override GeographicLocationsElement LoadOneByID(int pkid)
    //    {
    //        // Make sure we don't already have it.
    //        foreach (GeographicLocationsElement obj in this)
    //        {
    //            if (obj.Value == pkid)
    //                return (obj);
    //        }

    //        LU_GeographicLocationsTableAdapter adapter = new LU_GeographicLocationsTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        GeographicLocationsElement elem = null;
    //        dsLookups.LU_GeographicLocationsDataTable tbl = adapter.GetData(pkid, null);
    //        if (tbl.Rows.Count == 1)
    //        {
    //            dsLookups.LU_GeographicLocationsRow row = (dsLookups.LU_GeographicLocationsRow)tbl.Rows[0];
    //            elem = new GeographicLocationsElement(row.LU_GeographicLocationID, row.GeographicLocation, row.Description, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive);
    //            this.Add(elem);
    //        }

    //        return (elem);
    //    }

    //    #endregion
    //}

    //#endregion

    //#region LU_PostalCodes

    //public class PostalCodesElement : LookupElement
    //{
    //    #region Construction / Disposal

    //    public PostalCodesElement(int postalCodeID, string postalCode, int displayOrder, string version, bool isActive)

    //        : base(postalCodeID, postalCode, displayOrder, version, isActive)
    //    {
    //    }

    //    #endregion

    //    #region Public Properties

    //    //--------------------------------------------------------------------------
    //    // Aliases for the LookupElement.Value and LookupElement.Text fields.
    //    public int LU_PostalCodeID
    //    {
    //        get { return base.Value; }
    //        set { base.Value = value; }
    //    }


    //    public string PostalCode
    //    {
    //        get { return (base.Text); }
    //        set { base.Text = value; }
    //    }


    //    //--------------------------------------------------------------------------
    //    // Lookup table-specific fields/columns that are not already contained in LookupElement.
    //    // ...

    //    #endregion
    //}


    //public partial class PostalCodesLookup : Lookup<PostalCodesElement>
    //{
    //    #region Construction / Disposal

    //    public PostalCodesLookup()
    //    {
    //        this.Load(AppSettings.AppVersion);
    //    }

    //    #endregion

    //    #region Public Methods

    //    /// <summary>
    //    /// Load the lookup values from the database.
    //    /// </summary>
    //    public override void Load(string version)
    //    {
    //        LU_PostalCodesTableAdapter adapter = new LU_PostalCodesTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        dsLookups.LU_PostalCodesDataTable tbl = adapter.GetData(null, version);

    //        foreach (dsLookups.LU_PostalCodesRow row in tbl.Rows)
    //            this.Add(new PostalCodesElement(row.LU_PostalCodeID, row.PostalCode, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive));
    //    }


    //    /// <summary>
    //    /// Loads the single specified element if it's not already in the collection.
    //    /// </summary>
    //    public override PostalCodesElement LoadOneByID(int pkid)
    //    {
    //        // Make sure we don't already have it.
    //        foreach (PostalCodesElement obj in this)
    //        {
    //            if (obj.Value == pkid)
    //                return (obj);
    //        }

    //        LU_PostalCodesTableAdapter adapter = new LU_PostalCodesTableAdapter();
    //        adapter.Connection = AppSettings.GetDbConn();

    //        PostalCodesElement elem = null;
    //        dsLookups.LU_PostalCodesDataTable tbl = adapter.GetData(pkid, null);
    //        if (tbl.Rows.Count == 1)
    //        {
    //            dsLookups.LU_PostalCodesRow row = (dsLookups.LU_PostalCodesRow)tbl.Rows[0];
    //            elem = new PostalCodesElement(row.LU_PostalCodeID, row.PostalCode, row.DisplayOrder, row.IsVersionNull() ? null : row.Version, row.IsActive);
    //            this.Add(elem);
    //        }

    //        return (elem);
    //    }

    //    #endregion
    //}

    //#endregion
}
